home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / grafik / listgif / listgif.c next >
Encoding:
C/C++ Source or Header  |  1991-06-27  |  3.9 KB  |  157 lines

  1. /* LISTGIF - scans through all GIF files and reports size and colors */
  2.  
  3. #define INCL_DOSFILEMGR
  4.  
  5. #include <os2.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <dos.h>
  9.  
  10. void gif_stat(FILEFINDBUF *filespec);
  11. unsigned int getbytes(FILE *dev);
  12.  
  13. void main(int argc, char *argv[])
  14. {
  15.     int           i,
  16.                   count = 1;
  17.     FILEFINDBUF   filespec;
  18.     char          filename[90];
  19.     HDIR          filespec_handle = HDIR_SYSTEM;
  20.  
  21.     strcpy(filename, "*.GIF");
  22.     if (--argc)
  23.    {
  24.       strcpy(filename, argv[1]);
  25.    }
  26.  
  27.     if (DosFindFirst(filename, &filespec_handle, FILE_NORMAL, &filespec,
  28.                sizeof(filespec), &count, 0L) != 0)
  29.        {
  30.        printf("No GIFs here...\n");
  31.        return;
  32.        }
  33.     else
  34.        {
  35.        gif_stat(&filespec);
  36.  
  37.        while (DosFindNext( filespec_handle, &filespec, sizeof(filespec), &count) == 0)
  38.           gif_stat(&filespec);
  39.  
  40.        DosFindClose(filespec_handle);
  41.        }
  42.  
  43. }
  44.  
  45.  
  46. /* GIF_STAT - the main routine reads and displays the GIF info. */
  47. void gif_stat(FILEFINDBUF *filespec)
  48. {
  49.     char version[7];
  50.     int byte1, byte2 ,byte3;
  51.     int color_res, colors;
  52.     int bits_per_pix, bits_to_use;
  53.     int i;
  54.     unsigned int width;
  55.     unsigned int height;
  56.     char filenm[9];
  57.     FILE *infile;
  58.     int  hours,
  59.          minutes,
  60.          year,
  61.          month,
  62.          day;
  63.     char ampm;
  64.  
  65.  
  66.     /* Check for GIF filename */
  67.  
  68.      if ((infile = fopen (filespec->achName, "rb")) == NULL)
  69.        return;
  70.  
  71.      /* trim the ".GIF" off of the filename, for display purposes */
  72.      filespec->achName[strlen(filespec->achName)-4] = '\0';
  73.      printf("   %-8s  %3s  %8ld  ", filespec->achName, "GIF", filespec->cbFile);
  74.  
  75.  
  76.     /* pick out the various elements of the file's date and time */
  77.      year    = ((filespec->fdateLastWrite.year )   & 0x7F) + 80;
  78.       month   =  (filespec->fdateLastWrite.month)   & 0x0F;
  79.       day     =   filespec->fdateLastWrite.day      & 0x1F;
  80.       hours   =  (filespec->ftimeLastWrite.hours)   & 0x1F;
  81.       minutes =  (filespec->ftimeLastWrite.minutes) & 0x3F;
  82.  
  83.      if (hours > 12)
  84.      {
  85.          hours = hours - 12;
  86.          ampm  = 'p';
  87.      }
  88.      else
  89.          ampm  = 'a';
  90.          
  91.      printf("%2d-%02d-%02d", month, day, year);
  92.      printf("  %02d:%02d%c", hours, minutes, ampm);
  93.  
  94.     /* get version from file - no version = no picture */
  95.     if ((version[0] = getc(infile)) == 0x47) {
  96.       for (i = 1; (i < 6); i++)
  97.         version[i] = getc(infile);
  98.       version[6] = '\0';
  99.  
  100.       /* find picture width */
  101.       width = getbytes(infile);
  102.  
  103.       /* find picture height */
  104.       height = getbytes(infile);
  105.  
  106.       /* skip bytes for a Global Map */
  107.       byte1 = getc(infile);
  108.       byte2 = byte1 & 0x80;
  109.  
  110.       /* determine the color resolution */
  111.       byte2 = byte1 & 0x70;
  112.       color_res = byte2 >> 4;
  113.  
  114.       /* get the background index */
  115.       byte3 = getc(infile);
  116.  
  117.       /* determine the bits per pixel */
  118.       bits_per_pix = byte1 & 0x07;
  119.       bits_per_pix++;
  120.       bits_to_use = bits_per_pix;
  121.  
  122.       /* determine # of colors in global map */
  123.       colors = 1 << bits_per_pix;
  124.  
  125.       /* display the GIF information */
  126.       printf(" - [");
  127.       printf("%3d", width);
  128.       printf("x");
  129.       printf("%3d", height);
  130.       printf("x");
  131.       printf("%3d", colors);
  132.       printf("]\n");
  133.     }
  134.     else
  135.       printf(" - NOT A GIF FILE\n");
  136.  
  137.     fclose(infile);
  138. }
  139.  
  140. /* GETBYTES - routine to retrieve two bytes of information from the GIF */
  141. /*            file and then shift them into correct byte order.  The    */
  142. /*            information is stored in Least Significant Byte order.    */
  143.  
  144. unsigned int getbytes(FILE *dev)
  145. {
  146.     int byte1;
  147.     int byte2;
  148.     int result;
  149.  
  150.     /* read bytes and shift over */
  151.     byte1 = getc(dev);
  152.     byte2 = getc(dev);
  153.  
  154.     result = (byte2 << 8) | byte1;
  155.     return result;
  156. }
  157.